package com.ck.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * 上下文工具类
 *
 * @author linqiang
 * @version v1.0
 * @date 2018-09-05 10:11
 */
@Component
public class SpringContextUtil implements ApplicationContextAware {

    private ApplicationContext context;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.context = applicationContext;
    }

    /**
     * 获取当前环境
     *
     * @return string
     */
    public String getActiveProfile() {
        return context.getEnvironment().getActiveProfiles()[0];
    }
}
